<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

</body>
<script type="text/javascript">
	function baz() {
		var x = 1;
		return {
			foo : function foo() {
				return ++x;
			},
			bar : function bar() {
				return --x;
			}
		};
	}

	var closures = baz();

	console.log(closures.foo(), // 2
	closures.bar() // 1
	);
	
	
	//--- 
	var data = [];
 
	for (var k = 0; k < 3; k++) {
	  data[k] = function () {
	    alert(k);
	  };
	}
	data[0](); // 3, but not 0
	data[1](); // 3, but not 1
	data[2](); // 3, but not 2
</script>
</html>